#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define ll long long


int N, M, K;
int f[1001][1001];
int 
const ll mod = 1000000007ll;
ll _x, _y;
ll inv[1001];

    inline void extGcd(ll a, ll b)
    {
        if (b == 0)
        {
            _x = 1;
            _y = 0;
        }
        else
        {
            ll x, y;
            extGcd(b, a % b);
            x = _y;
            y = _x - (a / b) * _y;
            _x = x;
            _y = y;
        }
    }
    inline int invMod(int a)
    {
        extGcd(a, mod);
        _x %= mod;
        _x += mod;
        _x %= mod;
        return _x;
    }
    inline int fastPowMod(ll a, int b)
    {
        ll d = 1;
        while (b > 0)
        {
            if ((b & 1) > 0)
            {
                d = d * a;
                d %= mod;
            }
            a = a * a;
            a %= mod;
            b >>= 1;
        }
        return d;
    }
    
    inline int F(int n, int k)
    {
        if (k == 0)
            return 0;
        int res = 0;
        ll C = 1;
        for (int j = 0; j < k; j++)
        {
            if (j % 2 == 0)
                res += (f[N][k - j] * C) % mod;
            else res -= (f[N][k - j] * C) % mod;
            if (res >= mod) res -= mod;
            if (res < 0) res += mod;
            C *= (k - j);
            C %= mod;
            C *= inv[j + 1];
            C %= mod;
        }
        return res;
    }
    void solve() {
        int res = 0;
        ll C = M % mod;
        for (int k = 1; k <= K; k++)
        {
            res += (C * F(N, k)) % mod;
            if (res >= mod) res -= mod;
            if (res < 0) res += mod;
            C *= (M - k);
            C %= mod;
            C *= inv[k + 1];
            C %= mod;
        }
        cout << res << "\n";
    }

    int main()
    {
    	int T;
    	for (int i = 1; i <= 1000; i++)
    		inv[i] = invMod(i);
    	for (int i = 0; i <= 1000; i++)
    	{
    		f[0][i] = 1;
    		for (int j = 1; j <= 1000; j++)
    			f[j][i]	= ((ll)f[j - 1][i] * i) % mod;
    	}
    	cin >> T;
    	for (int i = 0; i < T; i++)
    	{
    		cin >> N >> M >> K;
    		solve();
    	}
    	return 0;

    }